package com.smcdd.cdb.dbo.cdb_dbo.ui.activity;

import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.smcdd.cdb.dbo.cdb_dbo.R;
import com.smcdd.cdb.dbo.cdb_dbo.service.presenter.PagePresenter;
import com.smcdd.cdb.dbo.cdb_dbo.service.view.IPage;
import com.smcdd.cdb.dbo.cdb_dbo.ui.base.BaseActivity;
import com.smcdd.cdb.dbo.cdb_dbo.ui.utils.ToastUtil;
import com.smcdd.cdb.dbo.cdb_dbo.ui.widget.PagePopup;

/**
 * 作者：Administrator on 2017/7/13 14:24
 * 邮箱：zhanghuaiha@gmail.com
 * 已安装设备分页
 *
 */

public class PageActivity extends BaseActivity<IPage,PagePresenter> implements IPage{
    private TextView sort,page_tv;
    private ImageView back;
    private RecyclerView recyclerView;
    private PagePopup titlePopup;
    private SwipeRefreshLayout page_srl;


    private PagePopup.OnItemOnClickListener onitemClick = (type0, type1, type2, type3,type4) -> {
   //   ToastUtil.showToast(type0+"!!!"+type1+"!!!!"+type2+"!!!!!"+type3);
        mPresenter.setType(type0,type1,type2,type3,type4);

    };
    public void initView() {
        sort = (TextView) findViewById(R.id.page_sort);
        back = (ImageView) findViewById(R.id.page_back);
        recyclerView = (RecyclerView) findViewById(R.id.page_recycler);
        page_srl = (SwipeRefreshLayout) findViewById(R.id.page_srl);
        page_tv = (TextView) findViewById(R.id.page_tv);
    }

    @Override
    public void initData() {
        initPopWindow();
        mPresenter.loadContacts();
        String status = getIntent().getStringExtra("status");
        if (status == null) {
            mPresenter.setType("-1","-1","-1","-1","-1");
        }else if (status.equals("1")) {
            //wifi在线
            mPresenter.setType("-1","1","-1","-1","1");
        }else if (status.equals("2")) {
            //wifi离线
            mPresenter.setType("-1","0","-1","-1","1");
        }else if (status.equals("3")) {
            //密码设备
            mPresenter.setType("-1","-1","-1","-1","4");
        }else if (status.equals("4")) {
            //纸巾机设备
            mPresenter.setType("-1", "-1", "-1", "-1", "5");
        }else {
            mPresenter.setType("-1","-1","-1","-1","-1");
        }

    }


    private void initPopWindow() {
        // 实例化标题栏弹窗
        titlePopup = new PagePopup(this, ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        titlePopup.setItemOnClickListener(onitemClick);
    }

    @Override
    public void initListener() {
        back.setOnClickListener(v -> finish());
        sort.setOnClickListener(v -> {
            titlePopup.show(findViewById(R.id.page_title));
        });
    }

    @Override
    protected PagePresenter createPresenter() {
        return new PagePresenter(this);
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_page;
    }

    @Override
    public RecyclerView getRv() {
        return recyclerView;
    }

    @Override
    public SwipeRefreshLayout getSrl() {
        return page_srl;
    }

    @Override
    public TextView getTV() {
        return page_tv;
    }
}
